package com.ruoyi.aitcommon.vo;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

public class AggVO <T>{
	private final String headname="headVO";
	private final String bodyname="bodyVOS";
	
	public T headVO;
	public List<T> bodyVOS;
	
	public AggVO() {
		super();
	}
	
	public AggVO(Map<String,Object> map) {
		super();
		
		this.headVO = (T) map.get(headname) ;
		this.bodyVOS = (List<T>) map.get(bodyname) ;
	}
	
	public Map<String,Object> toMap(){
		Map<String,Object> retmap=new LinkedHashMap<String,Object>();
		retmap.put(headname, this.headVO);
		retmap.put(bodyname, this.bodyVOS);
		return retmap;
	}
	
	public Map<String,Object> toMap(String head,String body){
		Map<String,Object> retmap=new LinkedHashMap<String,Object>();
		retmap.put(head, this.headVO);
		retmap.put(body, this.bodyVOS);
		return retmap;
	}
	
	@Override
	public String toString() {
		StringBuilder sb=new StringBuilder();
		for(T item : bodyVOS) {
			sb.append(item+"\r\n");
		}
		return "AggVO headVO=\r\n" + headVO + "\r\n, bodyVOS=\r\n" + sb.toString();
	}
	
//	通过JSON深度Clone
	public AggMap clone() {
		JSONObject json = (JSONObject)JSONObject.toJSON(this);
		AggMap newagg=JSONObject.toJavaObject(json, AggMap.class);
		return newagg;
	}
	
}
